africa <- read.csv("africa_polity.csv")
head(africa)
unique(africa$year)
mat <- matrix(nrow=21, ncol=1)

mat[1,1] <-mean(africa$xconst[africa$year==1992 & africa$xconst > 0])
mat[2,1] <-mean(africa$xconst[africa$year==1993 & africa$xconst > 0])
mat[3,1] <-mean(africa$xconst[africa$year==1994 & africa$xconst > 0])
mat[4,1] <-mean(africa$xconst[africa$year==1995 & africa$xconst > 0])
mat[5,1] <-mean(africa$xconst[africa$year==1996 & africa$xconst > 0])
mat[6,1] <-mean(africa$xconst[africa$year==1997 & africa$xconst > 0])
mat[7,1] <-mean(africa$xconst[africa$year==1998 & africa$xconst > 0])
mat[8,1] <-mean(africa$xconst[africa$year==1999 & africa$xconst > 0])
mat[9,1] <-mean(africa$xconst[africa$year==2000 & africa$xconst > 0])
mat[10,1] <-mean(africa$xconst[africa$year==2001 & africa$xconst > 0])
mat[11,1] <-mean(africa$xconst[africa$year==2002 & africa$xconst > 0])
mat[12,1] <-mean(africa$xconst[africa$year==2003 & africa$xconst > 0])
mat[13,1] <-mean(africa$xconst[africa$year==2004 & africa$xconst > 0])
mat[14,1] <-mean(africa$xconst[africa$year==2005 & africa$xconst > 0])
mat[15,1] <-mean(africa$xconst[africa$year==2006 & africa$xconst > 0])
mat[16,1] <-mean(africa$xconst[africa$year==2007 & africa$xconst > 0])
mat[17,1] <-mean(africa$xconst[africa$year==2008 & africa$xconst > 0])
mat[18,1] <-mean(africa$xconst[africa$year==2009 & africa$xconst > 0])
mat[19,1] <-mean(africa$xconst[africa$year==2010 & africa$xconst > 0])
mat[20,1] <-mean(africa$xconst[africa$year==2011 & africa$xconst > 0])
mat[21,1] <-mean(africa$xconst[africa$year==2012 & africa$xconst > 0])

plot(africa$xconst[africa$country=="Kenya"])
africa$xconst[africa$country=="Congo Brazzaville" & africa$year>1997]

roc <- c(rep(NA, 5), rep(1, 5), rep(2, 11))

pdf(file = "polity.pdf", height = 6, width = 10)
plot(mat, xlab = "Years", xaxt = "n", ylim = c(0,8), main = "Average Polity IV Executive Constraints Score 
(Sub-Saharan Africa)", ylab ="")

axis(1, at= 1:21, labels=seq(1992, 2012, by = 1))
lines(africa$xconst[africa$country=="Kenya" & africa$year<2008], lty = 2)
lines(roc, lty = 1)

legnames <- c("Congo","Kenya")
legend("topleft", legnames, col = c("black"), lty = c(1,2),  bty = "n")
dev.off()